<template>
  <a-card :bordered="false">
    <!-- 查询区域 -->
    <div class="table-page-search-wrapper">
      <a-form layout="inline" :form="form">
        <a-row :gutter="24">
          <a-col :md="6" :sm="24">
            <a-form-item label="OA申请单号">
              <a-input placeholder="OA申请单号" v-model="queryParam.oaRequestId"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="物料编码">
              <a-input placeholder="物料编码" v-model="queryParam.materialCode"></a-input>
            </a-form-item>
          </a-col>
          <a-col :md="6" :sm="24">
            <a-form-item label="状态">
              <a-select placeholder="申请单状态" v-model="queryParam.status" default-value="-1">
                <!-- <a-select-option value="-1">全部</a-select-option> -->
                <a-select-option value="1">创建</a-select-option>
                <a-select-option value="2">绑定物料编码</a-select-option>
                <a-select-option value="3">生成标签</a-select-option>
                <a-select-option value="4">制作</a-select-option>
                <a-select-option value="5">调试</a-select-option>
                <a-select-option value="6">验收</a-select-option>
                <a-select-option value="7">入库</a-select-option>
              </a-select>
            </a-form-item>
          </a-col>

          <a-col :md="6" :sm="24">
            <span style="float: left;overflow: hidden;" class="table-page-search-submitButtons">
              <a-button type="primary" @click="searchQuery" icon="search">查询</a-button>
              <a-button type="primary" @click="searchReset" icon="reload" style="margin-left: 8px">重置</a-button>
            </span>
          </a-col>
        </a-row>
      </a-form>
    </div>

    <!-- 操作按钮区域 -->
    <!--    <div class="table-operator">-->
    <!--      <a-dropdown >-->
    <!--        <a-button style="margin-left: 8px"> 批量操作 <a-icon type="down" /></a-button>-->
    <!--        <a-menu slot="overlay">-->
    <!--          <a-menu-item key="1" @click="batchDel"><a-icon type="delete"/>批量手动补全物料编码</a-menu-item>-->
    <!--        </a-menu>-->
    <!--      </a-dropdown>-->
    <!--    </div>-->

    <!-- table区域-begin -->
    <div>
      <div class="ant-alert ant-alert-info" style="margin-bottom: 16px;">
        <i class="anticon anticon-info-circle ant-alert-icon"></i> 已选择
        <a style="font-weight: 600">{{ selectedRowKeys.length }}</a
        >项
        <a style="margin-left: 24px" @click="onClearSelected">清空</a>
        <span style="float:right;">
          <a @click="loadData()"><a-icon type="sync" />刷新</a>
        </span>
      </div>

      <a-table
        ref="table"
        size="middle"
        rowKey="id"
        :columns="columns"
        :dataSource="dataSource"
        :pagination="ipagination"
        :loading="loading"
        :customRow="rowClick"
        :rowSelection="{ selectedRowKeys: selectedRowKeys, onChange: onSelectChange }"
        @change="handleTableChange"
      >
        <span slot="status_progress" slot-scope="text, record, index">
          <a-progress
            :strokeColor="getPercentColor(record.status)"
            :percent="getFlowRateNumber(record.status)"
            size="small"
          />
        </span>

        <span slot="action" slot-scope="text, record">
          <a @click="handleDetail(record)">详情</a>
          <a-divider type="vertical" />
          <a-dropdown>
            <a class="ant-dropdown-link">更多 <a-icon type="down"/></a>
            <a-menu slot="overlay">
              <a-menu-item :disabled="record.status === 1 ? true : false" @click="handleCreateFixTool(record)">
                <span><a-icon type="barcode" />&nbsp;生成标签</span>
              </a-menu-item>
              <a-menu-divider />
              <a-menu-item>
                <a-popconfirm title="确定关闭吗?" @confirm="() => handleDelete(record.id)">
                  <span> <a-icon type="delete" /> 关闭申请单</span>
                </a-popconfirm>
              </a-menu-item>
              <!--                <a-menu-item @click="()=>showDeleteConfirm(record.id)">-->
              <!--                  <span ><a-icon type="delete" />&nbsp;关闭申请单</span>-->
              <!--                </a-menu-item>-->
            </a-menu>
          </a-dropdown>
        </span>
      </a-table>
    </div>
    <!-- table区域-end -->

    <!-- 表单区域 -->
    <OAFixtureReq-modal ref="modalForm" @ok="modalFormOk"></OAFixtureReq-modal>

    <CreateFixtureTool-modal ref="fixtureModalForm" @ok="modalFormOk"></CreateFixtureTool-modal>
  </a-card>
</template>

<script>
import OAFixtureReqModal from './modal/OAFixtureReqModal'
import CreateFixtureToolModal from './modal/CreateFixtureToolModal'
import { JeecgListMixin } from '@/mixins/JeecgListMixin'

export default {
  name: 'OAFixtureReqList',
  mixins: [JeecgListMixin],
  components: {
    OAFixtureReqModal,
    CreateFixtureToolModal
  },
  data() {
    return {
      description: 'OA工装治具申请列表界面',
      // importExcelUrl:`${window._CONFIG['domianURL']}/test/jeecgOrderMain/importExcel`,
      // 表头
      columns: [
        {
          title: '序号',
          dataIndex: '',
          key: 'rowIndex',
          width: 50,
          align: 'center',
          customRender: function(t, r, index) {
            return parseInt(index) + 1
          }
        },
        {
          title: 'OA申请单标题',
          align: 'left',
          dataIndex: 'oaTitle'
        },
        {
          title: '项目编号',
          align: 'center',
          dataIndex: 'projNo'
        },
        {
          title: '项目名称',
          align: 'left',
          dataIndex: 'projName'
        },
        {
          title: '申请日期',
          align: 'center',
          dataIndex: 'requestDate'
        },
        {
          title: '需求数量',
          align: 'center',
          dataIndex: 'requestNum',
          customRender: (text, record, index) => {
            return text ? text + ' 台' : '/'
          }
        },
        {
          title: '实际制作',
          align: 'center',
          dataIndex: 'actualNum',
          customRender: (text, record, index) => {
            return text ? text + ' 台' : '/'
          }
        },
        {
          title: '申请发起人',
          align: 'center',
          dataIndex: 'oaReqUserName'
        },
        {
          title: '物料编码',
          align: 'center',
          dataIndex: 'materialCode',
          customRender: (text, record, index) => {
            return text ? text : '/'
          }
        },
        {
          title: '创建日期',
          align: 'center',
          dataIndex: 'createTime'
        },
        {
          title: '状态进度',
          align: 'center',
          dataIndex: 'status_progress',
          scopedSlots: { customRender: 'status_progress' }
        },
        {
          title: '操作',
          dataIndex: 'action',
          align: 'center',
          scopedSlots: { customRender: 'action' }
        }
      ],
      url: {
        list: '/oaFixtureReqCtrl/getOAReqList',
        delete: '/oaFixtureReqCtrl/delete'
        // deleteBatch: "/test/jeecgOrderMain/deleteBatch",
        // exportXlsUrl: "/test/jeecgOrderMain/exportXls",
      },
      form: this.$form.createForm(this)
    }
  },
  methods: {
    getPercentColor(value) {
      let p = Number(value)
      if (p >= 0 && p < 2) {
        return 'rgb(243,111,89)'
      } else if (p >= 7) {
        return 'rgb(87,213,2)'
      } else {
        return 'rgb(16, 142, 233)'
      }
    },
    getFlowRateNumber(value) {
      return Math.trunc(Number((value / 7) * 100))
    },
    rowClick: record => ({
      // 事件
      on: {
        click: () => {
          console.log('点击单行')
          console.log(record)
        }
      }
    }),

    handleCreateFixTool(record) {
      this.$refs.fixtureModalForm.open(record)
      //传递参数到子组件
      this.$refs.fixtureModalForm.title = '生成工装治具标签'
    },
    showDeleteConfirm(recordId) {
      this.$confirm({
        title: '确定关闭治具申请单吗?',
        content: '关闭申请单,将不会生成标签,不会在系统中生成治具信息',
        okText: '确定',
        okType: 'danger',
        centered: true,
        cancelText: '取消',
        onOk() {
          console.log('确认 删除 治具申请单' + recordId)
        },
        onCancel() {
          console.log('取消 删除 治具申请单')
        }
      })
    }
  }
}
</script>

<style scoped></style>
